import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useAuthStore } from './stores';

export const Root = () => {

  const { pathname } = useLocation();
  const { token } = useAuthStore.getState();

  if (pathname === '/') {
    //  return <Navigate to="/dashboard" />;
    if (token === undefined) {
      return <Navigate to="/login" />;

    }
    else {
      return <Navigate to="/dashboard/dashboards" />;
    }

  }

  return (
    <main>
      <Outlet />
    </main>
  )
}